//index.js
//获取应用实例
var app = getApp()

var indexVc = require('../index/index.js')

Page({
  data: {
    weekday: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
    showday: ['今天', '明天', ''],
    city:'', //城市
    district:'', //区域
    now:'',
    forecast:'',//七日天气预报
    quality:'' //空气质量
  },

  onShow: function () {
    var that = this;
    var city = app.globalData.defaultCity.slice(0, 2);
    that.setData({
      city: app.globalData.defaultCity, //今天天气情况数组 
      district: app.globalData.defaultCounty //生活指数
    });
    that.getWeather(city);//获得天气
  },

  //当页面加载完成
  onLoad: function () {
    var that = this;
    var date = new Date();
    console.log(date.getDay());
    that.setData({
      'showday[2]': this.data.weekday[(date.getDay() + 2) % 7],
    });
    console.log(this.data.showday); 
  },

  // //获取天气
  // getWeather: function (city) {
  //   var that = this;
  //   console.log('获取天气',city)

  //   indexVc.getWeather(city)
  //   that.setData({
  //         now: app.globalData.weatherData.now, //今天天气情况数组 
  //         forecast: app.globalData.weatherData.daily_forecast,
  //         quality: app.globalData.air
  //   });
  // },

  //获取天气
  getWeather: function (paramCity) {
    var city = app.globalData.defaultCity.slice(0, 2);//分割字符串
    var that = this;
    var url = "https://free-api.heweather.com/s6/weather";
    var param = {
      key: "c5bfaf6bf312400891a8bd572b751dec",
      location: city
    };
    //发出请求
    wx.request({
      url: url,
      data: param,
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log('2222', res);
        app.globalData.weatherData = res.data.HeWeather6[0];
        that.setData({
          now: app.globalData.weatherData.now, //今天天气情况数组 
          forecast: app.globalData.weatherData.daily_forecast,
          quality: app.globalData.air
          // weatherData: app.globalData.weatherData.now, //今天天气情况数组 
          // dress: res.data.HeWeather6[0].lifestyle[1] //生活指数
        });
            that.setData({
         
    });
      }
    })
  },
// 点击了 更换城市
  changeCityClick: function(outherCity) {
    
  }
});